import {
    bookCategory,
    addCategory,
    deleteCategory
} from '@/comApi'
import { amendCategory } from '../../../comApi';
import pub from "/src/lib/index.js";
const { getList } = pub
const ClassList = {
    state: {
        list:[]
    },
    mutations: {
        getTreeData(state,arr){
            state.list = arr
        },
    },
    actions: {
        getClass({commit},params={}) {
            return bookCategory(params)
                    .then(data => {
                    const { list } = data;
                    getList(list)
                    .then(data=>{
                        commit('getTreeData',data)
                    })
            })
        },
        addClass({dispatch},params={}) {
            return  addCategory(params)
                    .then(() => {
                        dispatch("getClass")
                    })
        },
        DeleteClass({dispatch},params={}){
            return  deleteCategory(params)
                    .then(() => {
                        dispatch("getClass")
                    })
        },
        amendClass({dispatch},params={}) {
            return amendCategory(params)
                    .then(() => {
                        dispatch("getClass")
                    })
        }
    },
    modules: {}
}

export default ClassList